<%-- 
    Document   : index
    Created on : 27-mar-2013, 10.06.16
    Author     : Giuseppe
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page import="ejb.Videogame"%>
<%@page import="ejb.RecensioneInterna"%>
<%@page import="ejb.Piattaforma"%>
<%@page import="ejb.Notizia"%>
<%@include file="wrapper.jsp" %>
<div class="container">

    <div class="row-fluid">

        <div class="span3 bs-docs-sidebar">
            <ul class="nav nav-list bs-docs-sidenav">
                <% if (request.getParameter("platform") != null) {%>
                <li><a href="Controller?button=visualizzaRecNot&platform=<%=request.getParameter("platform")%>&type=news"> <button class="btn btn-large btn-inverse btn-block" type="button"><i class="icon-white icon-th-list"></i> Notizie</button> </a></li>
                <li><a href="Controller?button=visualizzaRecNot&platform=<%=request.getParameter("platform")%>&type=reviews"><button class="btn btn-large btn-inverse btn-block" type="button"><i class="icon-white icon-th-list"></i> Recensioni</button> </a></li>
                <li><a href="Controller?button=visualizzaRecNot&platform=<%=request.getParameter("platform")%>&type=both"><button class="btn btn-large btn-inverse btn-block" type="button"><i class="icon-white icon-th-list"></i> Entrambe</button> </a></li>
                <%} else {%>
                <li><a href="Controller?button=visualizzaRecNot&platform=all&type=news"> <button class="btn btn-large btn-inverse btn-block" type="button"><i class="icon-white icon-th-list"></i> Notizie</button> </a></li>
                <li><a href="Controller?button=visualizzaRecNot&platform=all&type=reviews"><button class="btn btn-large btn-inverse btn-block" type="button"><i class="icon-white icon-th-list"></i> Recensioni</button> </a></li>
                <li><a href="Controller?button=visualizzaRecNot&platform=all&type=both"><button class="btn btn-large btn-inverse btn-block" type="button"><i class="icon-white icon-th-list"></i> Entrambe</button> </a></li>
                <%}%>
            </ul>
        </div>

        <div class="span6">
              <ul style="margin: 0;padding: 0;list-style-type:none">
       <%
               SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
                List<Notizia> l = (List<Notizia>) request.getAttribute("listNotizie");
                List<String> testoNotizie = (List<String>) request.getAttribute("testoNotizie");
                List<Piattaforma> pl = null;
                List<RecensioneInterna> r = (List<RecensioneInterna>) request.getAttribute("listRecensioni");
                List<String> testoRec = (List<String>) request.getAttribute("testoRecensioni");
                List<Videogame> vg = null;

                int i = 0, j = 0;
                int index;
                Notizia not = null;
                RecensioneInterna ri = null;
                if (l == null) {
                    l = new ArrayList<Notizia>();
                }
                if (r == null) {
                    r = new ArrayList<RecensioneInterna>();
                }
                if (!l.isEmpty()) {
                    not = l.get(i);
                }
                if (!r.isEmpty()) {
                    ri = r.get(j);
                }
                while (i < l.size() || j < r.size()) {

                    if (j == r.size() || (i < l.size() && not.getData().before(ri.getData()))) {
            %>
            <li class="thumbnail">
                
                <a href="Controller?button=visualizzaNotizia&platform=all&selezionato=<%=not.getId()%>" >
                    <h2  style="padding-left: 10px;color: #1F1F1F"><%=not.getTitolo()%> <b style="padding-top: 10px; padding-right: 20px; font-family: italic;font-size: 15px;float:right" > Notizia </b></h2> </a>  
                    
                <img  src="<%=not.getImmaginePath()%>" align="left" alt="" style="padding-left:10px;padding-top:5px;height:220px;width: 96%">
                
                <div class="caption">
                    
                    <h5>   <%
                        pl = not.getListPiattaforme();
                        for (Piattaforma p : pl) {
                            out.print(p.getNome() + " ");
                        }
                        index = (testoNotizie.get(i).length() < 100) ? testoNotizie.get(i).length() : 100;
                        %> <br> 
                        Autore: <%=not.getAutore().getNome()%> <%=not.getAutore().getCognome()%>   <br>  Data: <%=dateFormat.format(not.getData())%> </h5>
                        
                    <p><%=testoNotizie.get(i).substring(0, index) + "..."%></p>
                </div>
            </li>
            <% if (i < l.size() - 1) {
                    not = l.get(++i);
                } else {
                    i++;
                }
            } else {

            %>                

            <li class="thumbnail">
                <a href="Controller?button=visualizzaRecensione&platform=all&selezionato=<%=ri.getId()%>"> 
                    <h2  style="padding-left: 10px;color: #1F1F1F"><%=ri.getTitolo()%> <b style="padding-top: 10px; padding-right: 20px; font-family: italic;font-size: 15px;float:right" > Recensione </b></h2></a>

                <img src="<%=ri.getImmagini().get(0)%>" align="left" alt="" style="padding-left:10px;padding-top:5px;height:220px;width: 96%">
                <div class="caption">
                    <h5 >   <%
                        vg = ri.getVideogiochi();
                        for (Videogame v : vg) {
                            out.print(v.getNomeEPiattaforma() + " ");
                        }
                        index = (testoRec.get(j).length() < 100) ? testoRec.get(j).length() : 100;
                        %> 
                        <br> 
                        Autore: <%=ri.getAutore().getNome()%> <%=ri.getAutore().getCognome()%>   <br>  Data: <%=dateFormat.format(ri.getData())%></h5>

                    <p><%=testoRec.get(j).substring(0, index) + "..."%></p>
                </div>

            </li>
            <% if (j < r.size() - 1) {
                            ri = r.get(++j);
                        } else {
                            j++;
                        }
                    }
                }
            %>

            </ul>
       </div>
           <div class="span3"> 
			 <iframe src="https://www.google.com/calendar/embed?src=f7ni105q3cfp27s1t374amoqug%40group.calendar.google.com&ctz=Europe/Rome" style="border: 0" width="220" height="240" frameborder="0" scrolling="no" align="right">></iframe>

		

		</div>


</div>
</div>

</body>


</html>
